import java.util.LinkedList;
import java.util.Queue;

public class BinaryTree {
    class TreeNode{
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }

    void levelOrder(TreeNode root){
        if(root == null) return;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty())
        {
            TreeNode cur = queue.poll();
            System.out.println(cur.val);
            if(cur.left != null)
            {
                queue.offer(cur.left);
            }
            if(cur.right != null)
            {
                queue.offer(cur.right);
            }
        }
    }
    public boolean isCompleteTree(TreeNode root)
    {
        if(root == null) return true;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty())
        {
            TreeNode cur = queue.poll();
            if(cur != null)
            {
                queue.offer(cur.left);
                queue.offer(cur.right);
            }
            else
            {
                break;
            }
        }

        while(!queue.isEmpty())
        {
            TreeNode cur = queue.peek();
            if(cur == null) queue.poll();
            else return false;
        }
        return true;
    }

}
